package com.ddwl.shop.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.shop.QueryShopBannerBo;
import com.ddwl.schema.bo.shop.ShopBannerBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.shop.ShopBannerVo;
import com.ddwl.shop.service.ShopBannerService;
import com.ddwl.shop.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author Fu Zhaohui
 * @version 1.0.0.RELEASE
 * @date 2020/3/5 10:59 上午
 */
@Api(tags = "门店banner服务")
@RequestMapping("ShopBanner")
@RestController
public class ShopBannerController extends BaseController {

    @Resource
    private ShopBannerService bannerService;
    @Resource
    private ShopService shopService;

    @PostMapping("/create")
    @ApiOperation("创建Banner")
    @Auth(product = BaseEnum.ProductEnum.SHOP_CONSOLE)
    public RestVo create(@Valid @RequestBody ShopBannerBo bo) {
        bannerService.create(bo,getUserId(),getShopId());
        return RestVo.ok();
    }

    @PostMapping("/wbmCreate")
    @ApiOperation("创建wbmBanner")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo wbmCreate(@RequestBody ShopBannerBo bo) {
        
        String shopId = shopService.getShopIdByUserId(getUserId());
        bannerService.wbmCreate(bo,getUserId(),shopId);
        return RestVo.ok();
    }

    @PostMapping("/update")
    @ApiOperation("修改Banner")
    @Auth(product = BaseEnum.ProductEnum.SHOP_CONSOLE)
    public RestVo update(@Valid @RequestBody ShopBannerBo bo) {
        bannerService.update(bo,getUserId(),getShopId());
        return RestVo.ok();
    }

    @PostMapping("/effect")
    @ApiOperation("启用Banner")
    @Auth(product = BaseEnum.ProductEnum.SHOP_CONSOLE)
    public RestVo effect(@RequestParam Integer effect,@RequestParam String bannerId) {
        bannerService.effect(effect,getUserId(),getShopId(),bannerId);
        return RestVo.ok();
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除Banner")
    @Auth(product = BaseEnum.ProductEnum.SHOP_CONSOLE)
    public RestVo delete(@RequestParam String id) {
        bannerService.delete(id,getUserId(),getShopId());
        return RestVo.ok();
    }

    @GetMapping("/detailById/{shopId}")
    @ApiOperation("获取Banner明细 小程序")
    public RestVo<List<ShopBannerVo>> getBanner(@PathVariable String shopId) {
        return RestVo.ok(bannerService.getBanner(shopId));
    }

    @PostMapping("/detailByShopId")
    @ApiOperation("获取门店 Banner明细 商家后台")
    @Auth(product = {BaseEnum.ProductEnum.SHOP_CONSOLE})
    public RestVo<ShopBannerVo> detail(@RequestBody QueryShopBannerBo bo) {
        return RestVo.ok(bannerService.getByShopId(bo,getShopId()));
    }

    @PostMapping("/page")
    @ApiOperation("分页查询Banner 商家后台")
    @Auth(product = {BaseEnum.ProductEnum.SHOP_CONSOLE})
    public RestVo<PageVo<ShopBannerVo>> page(@Valid @RequestBody PageBo<QueryShopBannerBo> pageBo) {
        return RestVo.ok(bannerService.page(pageBo,getShopId()));
    }
    @PostMapping("/wbmPage")
    @ApiOperation("分页查询wbmBanner 商家后台")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo<PageVo<ShopBannerVo>> wbmPage(@Valid @RequestBody PageBo<QueryShopBannerBo> pageBo) {
        String shopId = shopService.getShopIdByUserId(getUserId());
        return RestVo.ok(bannerService.page(pageBo,shopId));
    }
}
